package com.hisoft.traffic.controller;

import com.hisoft.traffic.pojo.User;
import com.hisoft.traffic.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: ssmdemo
 * @description:
 * @author: wlg
 * @create: 2022-02-28 15:13:59
 **/
@Controller
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;
    @PostMapping("/login")
    @ResponseBody
    public Object login(
            @RequestParam("name") String userName,
            @RequestParam("pwd") String password,
            HttpSession session
    ){
        User user = userService.login(userName, password);
        Map<String,Integer> map = new HashMap<>();
        if (user != null) {
            session.setAttribute("user",user);
            map.put("code",200);
        }else {
            map.put("code",500);
        }
        return map;
    }

}
